//mui初始化
mui.init();
var subpages = ['toDoTab.html', 'hasDoTab.html'];
var subpage_style = {
	top: '46px',
	bottom: '0px'
};			
var aniShow = {};		
//创建子页面，首个选项卡页面显示，其它均隐藏；
mui.plusReady(function() {
	//首先，获取当前页，既是main.html
	var self = plus.webview.currentWebview();
	for (var i = 0; i < 2; i++) {
		var temp = {};
		//创建新的窗口，但是只显示首页，其他的隐藏
		var sub = plus.webview.create(subpages[i], subpages[i], subpage_style,{xtbh:self.xtbh});
		if (i > 0) {
			sub.hide();
		}else{
			temp[subpages[i]] = "true";
			mui.extend(aniShow,temp);
		}
		//添加子窗口
		self.append(sub);
	}
});
//当前激活选项
var activeTab = subpages[0];
var title = document.getElementById("title");
var title_icon=document.getElementById("title_icon");


 //选项卡点击事件
mui('.mui-bar-tab').on('tap', 'a', function(event) {

    var self = plus.webview.currentWebview();
	var targetTab = this.getAttribute('href');
	//如果点击的是当前页，直接返回。
	if (targetTab == activeTab) {
		return; 
	}
	//显示目标选项卡
	if(mui.os.ios||aniShow[targetTab]){
		plus.webview.show(targetTab,"fade-in",1,successCallback(self.xtbh,targetTab));
	}else{
		var temp = {};
		temp[targetTab] = "true";
		mui.extend(aniShow,temp);
		plus.webview.show(targetTab,"fade-in",300,successCallback(self.xtbh,targetTab));
	}
	//隐藏当前;
	document.getElementById(activeTab).style.fontSize="16px";
	document.getElementById(activeTab).style.color="rgb(246, 204, 204)";
	document.getElementById(targetTab).style.fontSize="18px";
	document.getElementById(targetTab).style.color="rgb(255,255,255)";
	plus.webview.hide(activeTab);
	//更改当前活跃的选项卡
	activeTab = targetTab;

});

//点击首页的时间
var firstpage = null;
//点击待办的时间
var todopage = null;
//点击已办的时间
var hasdopage = null;
//全局等待时间
var time = 5000;
//视图切换成功回调，为了重新请求数据
var successCallback=function(xtbh,activetab){	
	var activeview=plus.webview.getWebviewById(activetab);
	//打开待办
	if(activetab==subpages[0]){
		if (firstpage==null||(new Date().getTime() - firstpage > time)) {
			firstpage = new Date().getTime();
			mui.fire(activeview,'loadTodoData',{'xtbh':xtbh});
		}
	}
	//打开待办
	if(activetab==subpages[1]){
		if (todopage==null||(new Date().getTime() - todopage > time)) {
			todopage = new Date().getTime();
		mui.fire(activeview,'loadHasdoData',{'xtbh':xtbh});
		}
	}
}